﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Arsenal2
{
	static class Arsenal2
	{
		public static Dictionary<string, unit> Units = new Dictionary<string, unit>();
	}
	public class unit
	{
		public int Address;
		ProcessMemory PM;
		public String Name;
		public ushort time;
		public ushort gold;
		public ushort iron;
		public ushort fuel;
		public byte Point;
		public byte speed, armor;
		public ushort hp;

		byte unittype;
		byte visrange;
		public unit(ProcessMemory pm, int A)
		{
			PM = pm;
			Address = A;
			//Name = "";
			//for (int j = 0; j < 25 && mo[j] != 0; j++)
			//	Name += (char)mo[j];
			Name = pm.ReadString(A);
			unittype = pm.ReadBytes(A - 6, 1)[0];
			visrange = pm.ReadBytes(A - 1, 1)[0];

			hp = pm.ReadUInt16(A - 8);
			armor = pm.ReadBytes(A - 6, 1)[0];
			speed = pm.ReadBytes(A - 5, 1)[0];

			time = pm.ReadUInt16(A - 16);
			gold = pm.ReadUInt16(A - 14);
			fuel = pm.ReadUInt16(A - 12);
			iron = pm.ReadUInt16(A - 10);
			Point = pm.ReadBytes(A - 3, 1)[0];
			Console.WriteLine(Name + ":\t" + hp + "/" + armor + "\t" + gold + "/" + iron + "/" + fuel + "\t" + speed);
		}
		public void SetArmor(byte value)
		{
			armor = value;
			PM.WriteByte(Address - 6, value);
		}
		public void SetSpeed(byte value)
		{
			speed = value;
			PM.WriteByte(Address - 5, value);
		}
		public void SetTurn(byte value)
		{
			Point = value;
			PM.WriteByte(Address - 2, value);
		}
		public void SetPoint(byte value)
		{
			Point = value;
			PM.WriteByte(Address - 3, value);
		}
		public void SetGold(ushort value)
		{
			gold = value;
			PM.WriteInt16(Address - 14, (short)value);
		}
		public void SetFuel(ushort value)
		{
			fuel = value;
			PM.WriteInt16(Address - 12, (short)value);
			Console.WriteLine("Fuel set to " + value);
		}
		public void SetIron(ushort value)
		{
			iron = value;
			PM.WriteInt16(Address - 10, (short)value);
		}
		public void SetTime(ushort value)
		{
			time = value;
			PM.WriteUInt16(Address - 16, (ushort)value);
		}
		public void SetHP(ushort value)
		{
			hp = value;
			PM.WriteUInt16(Address - 8, (ushort)value);
		}

		public void SetParano()
		{
			PM.WriteByte(Address + 25, 0x21);
		}
		public void SetSchyzo()
		{
			PM.WriteByte(Address + 25, 0x19);
		}
	}
}
